package com.yx.shop.service.admin.impl;

import com.yx.shop.dao.admin.AdminProductDao;
import com.yx.shop.dao.admin.impl.AdminProductDaoImpl;
import com.yx.shop.entitly.Product;
import com.yx.shop.service.admin.AdminProductService;
import com.yx.shop.utils.JDBCUtils;

import java.util.List;

/**
 * @Classname AdminProductServiceImpl
 * @Description TODO:
 * @Date 2021/05/10 19:22
 * @Created by yx
 */
public class AdminProductServiceImpl implements AdminProductService {
    private AdminProductDao adminProductDao = new AdminProductDaoImpl();

    @Override
    public List<Product> getAllProduct() {
        List<Product> productList = null;
        try {
            JDBCUtils.begin();
            productList = adminProductDao.getAllProduct();
            JDBCUtils.commit();
        } catch (Exception e) {
            JDBCUtils.rollback();
            e.printStackTrace();
        }
        return productList;
    }

    @Override
    public boolean insertProduct(Product product) {
        boolean flag = false;
        try {
            JDBCUtils.begin();
            if (adminProductDao.insertProduct(product)>0) {
                flag=true;
            }
            JDBCUtils.commit();
        } catch (Exception e) {
            JDBCUtils.rollback();
            e.printStackTrace();
        }
        return false;
    }
}
